﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.IO;
using Newtonsoft.Json;

namespace Luncher
{
    public class PropsParser
    {
        public string setting;
        public string value;
    }
    public class SettingParser
    {
        public string Onwer = "Breadvm";
        public int Version = 1;
        public string Message = "";
        public string UUID = "";
        public List<PropsParser> Props = new List<PropsParser>();
    }
    class Setting
    {
        public string ConfigString = string.Empty;
        private SettingParser sp;

        public Setting() 
        {
            sp = new SettingParser();
        }
        public string LoadConfig(string config)
        {
            try
            {
                ConfigString = File.ReadAllText("setting.json");
                SettingParser jp = JsonConvert.DeserializeObject<SettingParser>(ConfigString);
            }
            catch
            {
                ConfigString = GenConfig("");
            }
            return ConfigString;
        }
        public string GenConfig(string uuid)
        {           
            sp.Message = "default";
            sp.UUID = uuid;
            sp.Props.Add(new PropsParser { setting = "ro.sf.lcd_density", value = "160" });
            sp.Props.Add(new PropsParser { setting = "gsm.operator.numeric", value = "46000" });// 46002 更改成中国境内电信公司
            sp.Props.Add(new PropsParser { setting = "xxb.wifi.mac", value = "00.E0.FC.5A.46.53" });//00.E0.FC 华为OUI
            sp.Props.Add(new PropsParser { setting = "xxb.phone.number", value = "13038937776" });
            sp.Props.Add(new PropsParser { setting = "xxb.phone.imsi", value = "46000123456784673" });
            sp.Props.Add(new PropsParser { setting = "xxb.phone.serialno", value = "215526567568509700" });
            sp.Props.Add(new PropsParser { setting = "xxb.device.imei", value = "250123456789013" });
            sp.Props.Add(new PropsParser { setting = "xxb.device.imeisv", value = "250123456789019" });
            //sp.Props.Add(new PropsParser { setting = "xxb.SSID", value = "Arrows" });
            //sp.Props.Add(new PropsParser { setting = "xxb.BSSID", value = "00:E0:FC:5A:46:55" });
            sp.Props.Add(new PropsParser { setting = "ro.zygote.disable_gl_preload", value = "true" });

            sp.Props.Add(new PropsParser { setting = "ro.product.manufacturer", value = "HUAWEI" });
            sp.Props.Add(new PropsParser { setting = "ro.product.brand", value = "HUAWEI" });
            sp.Props.Add(new PropsParser { setting = "ro.product.board", value = "NXT-AL10" });
            sp.Props.Add(new PropsParser { setting = "ro.product.hardwareversion", value = "HL1NEXTM" });
            sp.Props.Add(new PropsParser { setting = "ro.product.model", value = "HUAWEI NXT-AL10" });
            sp.Props.Add(new PropsParser { setting = "ro.build.description", value = "NXT-AL10-user 6.0 HUAWEINXT-AL10 C00B197 release-keys" });
            sp.Props.Add(new PropsParser { setting = "ro.build.display.id", value = "NXT-AL10C00B197" });
            sp.Props.Add(new PropsParser { setting = "ro.build.fingerprint", value = "HUAWEI/NXT-AL10/HWNXT:6.0/HUAWEINXT-AL10/C00B197:user/release-keys" });
            sp.Props.Add(new PropsParser { setting = "ro.serialno", value = "1234567890" });
            sp.Props.Add(new PropsParser { setting = "gsm.current.phone-type", value = "1" });
            sp.Props.Add(new PropsParser { setting = "gsm.sim.state", value = "READY" });
            sp.Props.Add(new PropsParser { setting = "gsm.sim.operator.numeric", value = "46000" });
            sp.Props.Add(new PropsParser { setting = "gsm.sim.operator.iso-country", value = "cn" });;
            sp.Props.Add(new PropsParser { setting = "gsm.sim.operator.iso-alpha", value = "China Telecom" });
            sp.Props.Add(new PropsParser { setting = "gsm.version.baseband", value = @"CBP8.2,21.750.02.00.031" });
            sp.Props.Add(new PropsParser { setting = "gsm.network.type", value = "UMTS" });//"unknown","GPRS","EDGE","UMTS"
            sp.Props.Add(new PropsParser { setting = "gsm.version.ril-impl", value = "android reference-ril 1.0" });
            sp.Props.Add(new PropsParser { setting = "ro.telephony.default_network", value = "1" });
            //sp.Props.Add(new PropsParser { setting = "qemu.hw.mainkeys", value = "0" });
            sp.Props.Add(new PropsParser { setting = "persist.service.bdroid.bdaddr", value = "00.E0.FC.5A.46.54" });//蓝牙 MAC
            sp.Props.Add(new PropsParser { setting = "ro.build.version.release", value = "6.0" });//web
            sp.Props.Add(new PropsParser { setting = "ro.build.id", value = "HUAWEINXT-AL10" });//web
            ConfigString = JsonConvert.SerializeObject(sp);
            return ConfigString;
        }
        public void SaveConfig()
        {
        }
        public void AddProps(string s, string v)
        {
            sp.Props.Add(new PropsParser { setting = s, value = v });
        }
    }
}
